import { defineStore } from "pinia";
import { ref,reactive } from 'vue';
export const useAppStore = defineStore("app",()=>{
    // 设备类型
    const device = ref('desktop');
    // 语言
    const language = ref('zh-cn');
    // 布局大小
    const size = ref('default');
    // 侧边栏状态
    const sidebarStatus = ref('closed');
    const sidebar = reactive({
        opened: sidebarStatus === 'opened',
        withoutAnimation: false,
    });

    // 顶部菜单激活路径
    const activeTopMenuPath = ref("");

    // 切换侧边栏
    function toggleSidebar() {
        sidebar.opened = !sidebar.opened;
        sidebarStatus.value = sidebar.opened
        ? 'opened'
        : 'closed';
    }
    // 关闭侧边栏
    function closeSideBar() {
        sidebar.opened = false;
        sidebarStatus.value = 'closed';
    }

    // 打开侧边栏
    function openSideBar() {
        sidebar.opened = true;
        sidebarStatus.value = 'opened';
    }

    // 切换设备
    function toggleDevice(val) {
        device.value = val;
    }

    /**
     * 改变布局大小
     *
     * @param val 布局大小 default | small | large
     */
    function changeSize(val) {
        size.value = val;
    }

    /**
     * 混合模式顶部切换
     */
    function activeTopMenu(val) {
        activeTopMenuPath.value = val;
    }
    return {
        device,
        language,
        size,
        sidebar,
        activeTopMenuPath,
        toggleSidebar,
        closeSideBar,
        openSideBar,
        toggleDevice,
        changeSize,
        activeTopMenu,
    }
});